<template>
	<view>
		<u-navbar @leftClick="back" title="登录" :autoBack="false" :placeholder="true"></u-navbar>
		<view class="content">
			<view style="display: flex; justify-content: center;">
				<u-image src="https://renovationcdn.jiachuangnet.com/allNewLogo.png" width="200rpx" height="200rpx"
					radius="10"></u-image>
			</view>
			<view style="text-align: center;font-size:14px;margin:30px 0;color:#787878;">
				速工装APP
			</view>
			<u--form :model="form" ref="uForm">
				<u-form-item label="账号:" prop="account" borderBottom>
					<u-input v-model="form.account" type="text" placeholder="请输入账号" clearable />
				</u-form-item>
				<u-form-item label="密码:" prop="password" borderBottom>
					<u-input v-model="form.password" type='password' clearable placeholder="请输入密码" />
				</u-form-item>
				<u-form-item>
					<view class="flex alignItem bewteen " style="width: 100%;">
						<!-- <text :style="{color:color}" @click="toPathB('reg')">去注册</text> -->
						<text style="color:#787878" @click="toPathC('forgetPwd')">忘记密码?</text>
					</view>
				</u-form-item>
				<u-form-item>
					<view style="margin-top: 30px;width: 100%;">
						<u-button @click="submit" shape="circle" :color='color'>登录</u-button>
					</view>
				</u-form-item>
			</u--form>
		</view>
		<view
			style="width:100%;position: absolute;bottom: 100rpx;left: 0;display: flex;justify-content: center;align-items: center;">
			<view>
				<u-checkbox-group :activeColor='color' v-model="checkboxValue" placement="column" >
					<u-checkbox v-for="(item, index) in checkboxList" :key="index" :name="item.name" >
					</u-checkbox>
				</u-checkbox-group>
			</view>
			<text>阅读并同意</text>
			<text style="margin:0 10rpx;text-decoration: underline;" :style="{'color':color}"
				@click="toPath('userAgreement')">用户协议</text>
			<text>及</text>
			<text style="margin:0 10rpx;text-decoration: underline;" :style="{'color':color}"
				@click="toPath('privacy')">隐私协议</text>
		</view>
	</view>
</template>

<script>
	let app = getApp();
	export default {
		data() {
			return {
				color: app.globalData.defaultColor,
				form: {
					account: '',
					password: ''
				},
				checkboxValue: [], 
				checkboxList: [{
						name: '同意'
					},

				],// 基本案列数据
				repath: '',
				load: 0
			}
		},
		methods: {
			toPathB(url) {
				uni.navigateTo({
					url: '/packageB/pages/' + url + '/index'
				})
			},
			toPathC(url) {
				console.log(url)
				uni.navigateTo({
					url: '/packageC/pages/' + url + '/index'
				})
			},
			toPath(url) {

				uni.navigateTo({
					url: '/pages/' + url + '/index'
				})
			},
			back() {
				uni.reLaunch({
					url: '/pages/mine/index'
				})
			},
			submit() {
				for (let i in this.form) {
					if (!this.form[i]) {
						uni.$u.toast('请填写账号密码!');
						return;
					}
				}
				if (this.checkboxValue[0] !== '同意') {
					uni.$u.toast('请阅读并同意用户及隐私协议!');
					return;
				}
				if (this.load == 1) {
					return uni.showLoading({
						title: '请勿重复提交 :)'
					});
				}
				this.load = 1
				let params = {
					username: this.form.account,
					password: this.form.password,
					loading: true
				}

				uni.$u.http.post('/user/login', params).then(res => {
					this.load = 0
					if (res) {
						uni.setStorageSync('isLogin', 'yes');
						if (res.userName) {
							uni.setStorageSync('userName', res.userName)
						}
						if (res.brandPartyId) {
							uni.setStorageSync('brandPartyId', res.brandPartyId)
						}
						if (res.phoneNum) {
							uni.setStorageSync('phoneNum', res.phoneNum)
						}
						if (res.userId) {
							uni.setStorageSync('userId', res.userId)
						}
						if (res.token) {
							uni.setStorageSync('token', res.token)
						}
						if (res.password) {
							uni.setStorageSync('password', res.password)
						}
						if (res.loginType) {
							uni.setStorageSync('loginType', res.loginType);
						}
						if (res.companyId) {
							uni.setStorageSync('companyId', res.companyId);
						}
						uni.setStorageSync('prompt', 'yes')
						uni.navigateTo({
							url: '/pages/mine/index'
						})
					}



				}).catch(err => {

				})
			}
		},
	}
</script>
<style>
	page {
		background-color: white !important;
	}
</style>
<style lang="scss" scoped>
	.content {
		position: absolute;
		width: 80%;
		top: 20%;
		left: 50%;
		transform: translate(-50%, 0);
	}
</style>